import { TVResource } from '../model/comm/tv-resource';
import { SubArea } from '../model/report/sub-area';
import { ConfigData } from '../model/comm/config-data';
import { CommService } from './comm.service';
import * as Enumerable from 'linq';
import { ReportUrls } from 'app/ptpmc/comm/report.urls.conf';
export class GlobalDataManager {
    private static tvResources: TVResource[];
    private static spcResources: TVResource[];
    private static subAreas: SubArea[];
    private static configData: ConfigData;

    public static projectSelected: any;

    constructor(private commservices: CommService) {

    }

    public static getProjectSelected() {
        if (!this.projectSelected) {
            this.projectSelected = Enumerable.from(GlobalDataManager.getProjects())
                .where(u => u.projectName === 'GF9').first();
        }
        return this.projectSelected;
    }

    public static getTVResources() {
        return this.tvResources;
    }
    public static setTVResources(items: TVResource[]) {
        this.tvResources = items;
    }
    public static getSPCResources() {
        return this.spcResources;
    }
    public static setSPCResources(items: TVResource[]) {
        this.spcResources = items;
    }
    public static getSubAreas() {
        return this.subAreas;
    }
    public static setSubAreas(items: SubArea[]) {
        this.subAreas = items;
    }
    public static getConfigData() {
        return this.configData;
    }
    public static SetConfigData(configData: ConfigData) {
        this.configData = configData;
    }
    public static getProjects() {
        return this.configData.projects;
    }

    public static changeShop(shopName){
        ReportUrls.BaseUrl = Enumerable.from(GlobalDataManager.getProjects())
            .where(u => u.projectName === shopName).first().apiUrl;
        

        GlobalDataManager.projectSelected = Enumerable.from(GlobalDataManager.getProjects())
            .where(u => u.projectName === shopName).first();
    }
}